package scratch.InfoEssentials;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.io.ObjectInputStream.GetField;

import javax.sound.sampled.Clip;
import javax.swing.SwingUtilities;

public class InfoEssentials {
	// user info
	private String username = null;

	private String password = null;
	private String cookie = "BQRUBwowBFMGV15TVgZSAlABBAUHUFkKUQRSVloBVQJVXlVaAVRq";

	// InfoNode
	private InfoNode infoNode = null;

	/* Singleton */
	private static InfoEssentials essenitals = new InfoEssentials();

	private InfoEssentials() {
	}

	public static InfoEssentials getInstance() {
		return essenitals;
	}
	
	private boolean addURL(String url) {
		if ((infoNode != null) && (infoNode.getUrl() == url)) {
			return false;
		} else {
			infoNode = new InfoNode(url);
			return true;
		}
	}

	private boolean process(String url) {
		if(cookie == null){
			return false;
		}else{
			NetAccess.setCookieValue(cookie);
		}
		
		this.addURL(url);
		
		FetchInfo.fetch(infoNode);
		
		return true;
	}	
	

	public void setUsername(String username) {
		this.username = username;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setCookie(String cookie) {
		this.cookie = cookie;
	}
	
	//clip the content to system clip board
	public static void clip(String content) {
		Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); 
		StringSelection itemInfo = new StringSelection(content); 
		clipboard.setContents(itemInfo, itemInfo);
	}

	public static void main(String[] args) {
		// clip("A\tB\tC\t123\tE\t");
		InfoEssentials ie = InfoEssentials.getInstance();
		ie.process("http://bbs.qshpan.com/read.php?tid=1056384&fpage=0&page=2");
	}

}
